package com.hhu.wangzb.server.handler;


import com.hhu.wangzb.common.exception.CustomException;
import com.hhu.wangzb.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public R handleCustomizedException(CustomException e) {

        log.warn(e.getMessage());

        return R.error(e.getCode(), e.getMessage());
    }
}
